package br.com.registrofinancas.view;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.Toast;

public class ETSaldoMovimentoOrigem extends EditText{
	private Double valor;
	private Double saldo;
	private Context contexto;
	
	public ETSaldoMovimentoOrigem(Context context) {
		super(context);
		this.contexto = context;
	}
	
	public ETSaldoMovimentoOrigem(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.contexto = context;
	}
	
	public ETSaldoMovimentoOrigem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.contexto = context;
	}

	public Double getValor() {
		return valor;
	}

	public void setValor(Double valor) {
		this.valor = valor;
	}

	public Double getSaldo() {
		return saldo;
	}

	public void setSaldo(Double saldo) {
		this.saldo = saldo;
	}
	@Override
	protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect){
		super.onFocusChanged(focused, direction, previouslyFocusedRect);
		if(!focused){
			if(!this.getText().toString().isEmpty()){
				Double valor = Double.valueOf(this.getText().toString());
				if(valor > saldo){
					Toast.makeText(contexto, "Teste", Toast.LENGTH_SHORT).show();
				}else{
					this.valor = valor;
				}
			}
		}
			
	}
}
